/* @(#)ProductType.java    V1.0
 *
 * Project: APEP 
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *       {CREATE_TIME} First release
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2007 Auto-Parts E-Procurement Co., Ltd. 
 *        No.251-1 Wuning Road, Shanghai, 200063, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Auto-Parts E-Procurement Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with APEP.
 *
 * Warning:
 * =============================================================================
 *   
 * 
 */

package system.base;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import system.data.ProductTypeBase;
import system.data.StorageMonthOutPageData;
import framework.core.*;

/*
	Author    :
	CreateTime:{CREATE_TIME}
*/
public class ProductType extends ProductTypeBase 
{

//----system generated start----// 	
	private static final String SEQ_NAME = "S_PRODUCT_TYPE";
public ProductType() 
{
	
}

private static void delete(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	delete(con,TABLE_NAME,conditions);
}
public static ProductType fetch()
{
	return new ProductType();
}
public static ProductType copy(ProductType srcObj)
{
	ProductType obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}

public static ProductType fetchByProductId(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(PRODUCT_ID,id);
	
	return fetch(con,conditions);
}


//得到区域下的产品分类
public static List getProductTypeList(DBConnection con) throws Exception{
    List list  = new ArrayList();
    String sql = "select distinct "+ProductType.PRODUCT_TYPE + " from " + ProductType.TABLE_NAME;

   
    DBResult result = DBEngine.doSelect(con,sql);
    
    ResultSet rs=result.getRs();
    
    while(rs.next())
    {
    	ProductType data = new ProductType();
        data.setProductType(rs.getInt(1));
        list.add(data);
    }    

    return list;    
}

//得到区域下的招标分类
public static List getProductBidList(DBConnection con,String productType) throws Exception{
    List list  = new ArrayList();
    String sql = "select distinct a."+ProductType.PRODUCT_TYPE +",a."+ProductType.IS_BID +",b."+ProductTypeManager.TYPE_NAME +" from " + ProductType.TABLE_NAME + " a";
    sql+=" left join "+ProductTypeManager.TABLE_NAME +" b on a."+ProductType.IS_BID+"=b."+ProductTypeManager.PRODUCT_TYPE;
    sql+=" where a."+ProductType.STATUS+"=1 and b."+ProductTypeManager.UPPER_TYPE+"=2000";;
    if(!"".equals(productType)){
    	sql+= " and a." + ProductType.PRODUCT_TYPE + " = "+productType;
    }
    
    sql+= " order by a."+ProductType.IS_BID;
    
    DBResult result = DBEngine.doSelect(con,sql);
    ResultSet rs=result.getRs();
   
    while(rs.next()){
    	ProductType data = new ProductType();
    	data.setProductType(rs.getInt(1));
        data.setIsBid(rs.getInt(2));
        data.setRemark(rs.getString(3));
        list.add(data);
    }
    return list;    
}

//得到招标分类下的供应商
public static List getProviderList(DBConnection con,String isBid) throws Exception{
    List list  = new ArrayList();
    String sql = "select distinct a."+ProductType.PRODUCT_TYPE+",a."+ProductType.IS_BID +",a."+ProductType.PROVIDER_CODE +",b."+Provider.NAME +" from " + ProductType.TABLE_NAME + " a";
    sql+=" left join "+Provider.TABLE_NAME +" b on a."+ProductType.PROVIDER_CODE+"=b."+Provider.CODE;
    sql+=" where a."+ProductType.STATUS+"=1" +" and b."+Provider.STATUS+"=1" ;
    if(!"".equals(isBid)){
    	sql+= " and a." + ProductType.IS_BID + " = "+isBid;
    }
    
    sql+= " order by a."+ProductType.PROVIDER_CODE;
    
    DBResult result = DBEngine.doSelect(con,sql);
    ResultSet rs=result.getRs();
    while(rs.next()){
    	ProductType data = new ProductType();
    	data.setProductType(rs.getInt(1));
        data.setIsBid(rs.getInt(2));
        data.setProviderCode(rs.getString(3));
        data.setRemark(rs.getString(4));
        list.add(data);
    }
    return list;    
}

public static ProductType fetch(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	return fetch(con,conditions);
}
public static ProductType fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		ProductType obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static ProductType fetch(java.sql.ResultSet rs) throws Exception
{
	ProductType obj = new ProductType();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//

}

